package gre.db;

import java.sql.*;

/**
 *
 * @author nacuong
 */
public class DBHelper {
  public static int getTableSize(Statement stmt, String table) throws SQLException{
    ResultSet results = stmt.executeQuery("SELECT COUNT(*) FROM " + table);
    results.next();
    return results.getInt(1);
  }

  /**
   * Get the location of jar/classes executing file
   * @return
   */
  public static String getCurrentPath(){
    String path = "";
    
    DBHelper dbHelper = new DBHelper();
    String classPath = dbHelper.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
    String[] folders = classPath.split("/");

    for (int inx = 1; inx < folders.length-1; inx++)
      path += folders[inx] + "/";

    return path + "data/";
  }
}
